package jjn.round1;

/**
 * @author Jjn
 * @since 2022-08-15 18:37
 */
public class SortingAlgorithm_ShellSort implements SortAlgorithm {
    
    @Override
    public void sort(int... nums) {
        int length = nums.length;
        int temp;
        for (int step = length / 2; step >= 1; step /= 2) {
            for (int i = step; i < length; i++) {
                temp = nums[i];
                int j = i - step;
                while (j > 0 && nums[j] > temp) {
                    nums[j + step] = nums[j];
                    j -= step;
                }
                nums[j + step] = temp;
            }
        }
    }
    
    @Override
    public String getName() {
        return "Shell sort";
    }
}
